
// Windows Script Host APIS

declare var ActiveXObject: { new (s: string): any; };

interface IWScriptStringCollection {
    Item(n: number): string;
    Count: number;
    length: number;
}

interface IWScriptTextCore {
    Close(): void;
    Column: number;
    Line: number;
}

interface IWScriptTextReader extends IWScriptTextCore  {
    Read(chars: number): string;
    ReadAll(): string;
    ReadLine(): string;
    Skip(chars: number): void;
    SkipLine(): void;
    AtEndOfLine: bool;
    AtEndOfStream: bool;
}

interface IWScriptTextWriter extends IWScriptTextCore {
    Write(s: string): void;
    WriteLine(s: string): void;
    WriteBlankLines(intLines: number): void;
}

interface INamedStringCollection extends IWScriptStringCollection {
    Exists: (name: string) => bool;
}

interface IWScriptArguments extends IWScriptStringCollection {
    Named: INamedStringCollection;
    Unnamed: IWScriptStringCollection;
    ShowUsage(): void;
}

declare var WScript: {
    Arguments: IWScriptArguments;
    FullName: string;
    Interactive: bool;
    Name: string;
    Path: string;
    ScriptFullName: string;
    ScriptName: string;
    StdErr: IWScriptTextWriter;
    StdOut: IWScriptTextWriter;
    StdIn: IWScriptTextReader;
    Echo(s: any);
    Quit(exitCode?: number);
    Sleep(time: number): void;

    CreateObject(progId: string, eventPrefix?: string): any;
    GetObject(pathName: string, progID?: string, eventPrefix?: string): any;
    ConnectObject(obj: any, eventPrefix?: string): void;
    DisconnectObject(obj: any): void;
}

interface IWshShortcut {
    TargetPath: string;
    FullName: string;
    Save: () => void;

    // Not used for URL Shortcuts
    Arguments: IWScriptStringCollection;
    // Not used for URL Shortcuts
    Description: string;
    // Not used for URL Shortcuts
    Hotkey: string;
    // Not used for URL Shortcuts
    IconLocation: string;
    // Not used for URL Shortcuts
    WindowStyle: number;
    // Not used for URL Shortcuts
    WorkingDirectory: string;
}

interface IWScriptExec {
    Status: number;
    StdErr: IWScriptTextWriter;
    StdOut: IWScriptTextWriter;
    StdIn: IWScriptTextReader;
    Terminate: () => void;
}

interface WshShell {
    CurrentDirectory: string;
    Environment: (envContext?: string) => IWScriptStringCollection;
    SpecialFolders: (folderName: string) => string;
    AppActivate: (title: string) => void;
    CreateShortcut: (pathname: string) => IWshShortcut;
    ExpandEnvironmentStrings: (envString: string) => string;
    LogEvent: (type: number, message: string, target?: string) => bool;
    Popup: (text: string, secondsToWait?: number, title?: string, buttonType?: number) => number;
    RegDelete: (name: string) => void;
    RegRead: (name: string) => any;
    RegWrite: (name: string, value: any, type?: string) => void;
    SendKeys: (keys: string) => void;
    Run: (command: string, windowsStyle?: number, waitOnReturn?: bool) => number;
    Exec: (command: string) => IWScriptExec;
}

interface WshNetwork {
    ComputerName: string;
    UserDomain: string;
    UserName: string;
    EnumerateNetworkDrives: () => IWScriptStringCollection;
    MapNetworkDrive: (localName: string, remoteName: string, updateProfile?: bool, user?: string, password?: string) => void;
    RemoveNetworkDrive: (localName: string, force?: bool, updateProfile?: bool) => void;
}

interface WshRemoteError { 
    Description: string;
    Line: number; 
    Character: number; 
    SourceText: string; 
    Source: string; 
    Number: number;
}

interface WshRemote {
    Status: number;
    Error: WshRemoteError;
    Execute: () => void;
    Terminate: () => void;
}

interface WshController {
    CreateScript: (commandLine: string, machineName?: string) => WshRemote;
}

// FileSystemObject

interface IFSODrive {
    AvailableSpace: number;
    DriveLetter: string;
    DriveType: number;
    FileSystem: string;
    FreeSpace: number;
    IsReady: bool;
    Path: string;
    RootFolder: string;
    SerialNumber: string;
    ShareName: string;
    TotalSize: number;
    VolumeName: string;
}

interface IFSOTextStream extends IWScriptTextWriter, IWScriptTextReader { }

interface IFSOFileSystemItem {
    Copy: (dest: string, overwrite?: bool) => void;
    Delete: (force?: bool) => void;
    Move: (dest: string) => void;
    Attributes: number;
    DateCreated: Date;
    DateLastAccessed: Date;
    DateLastModified: Date;
    Drive: IFSODrive;
    Name: string;
    Path: string;
    ShortName: string;
    ShortPath: string;
    Size: number;
    Type: string;
    ParentFolder: IFSOFolder;
}

interface IFSOFileSystemCollection {
    atEnd: () => bool;
    moveNext: () => void;
    Count: number;
}

interface IFSOFileCollection {
    item: () => IFSOFile;
}

interface IFSOFolderCollection {
    item: () => IFSOFolder;
}

interface IFSODriveCollection {
    item: () => IFSODrive;
}

interface IFSOFolder extends IFSOFileSystemItem {
    Files: IFSOFileCollection;
    SubFolders: IFSOFolderCollection;
    IsRootFolder: bool;
}

interface IFSOFile extends IFSOFileSystemItem {
    OpenAsTextStream: (iomode?: number, format?: number) => IFSOTextStream;
    Type: string;
}

interface IFileSystemObject {
    Drives: IFSODriveCollection;
    BuildPath: (path: string, name: string) => string;
    CopyFile: (source: string, dest: string, overwrite?: bool) => void;
    CreateFolder: (name: string) => IFSOFolder;
    CreateTextFile: (fileName: string, overwrite?: bool, unicode?: bool) => IFSOTextStream;
    DeleteFile: (filespec: string, force?: bool) => void;
    DeleteFolder: (folderspec: string, force?: bool) => void;
    DriveExists: (driveOrPathSpec: string) => bool;
    FileExists: (fileSpec: string) => bool;
    FolderExists: (folderSpec: string) => bool;
    GetAbsolutePathName: (relPath: string) => string;
    GetBaseName: (filename: string) => string;
    GetDrive: (driveSpec: string) => IFSODrive;
    GetDriveName: (fullPath: string) => string;
    GetExtension: (path: string) => string;
    GetFile: (filePath: string) => IFSOFile;
    GetFileVersion: (filePath: string) => string;
    GetFileName: (fileSpec: string) => string;
    GetFolder: (fldrSpec: string) => IFSOFolder;
    GetParentFolderName: (path: string) => string;
    GetSpecialFolder: (which: number) => IFSOFolder;
    GetTempName: () => string;
    MoveFile: (sourceSpec: string, dest: string) => void;
    MoveFolder: (sourceSpec: string, dest: string) => void;
    OpenTextFile: (path: string, iomode?: number, create?: bool, format?: number) => IFSOTextStream;
}